<?php
/**
 * Created by PhpStorm.
 * User: 29620
 * Date: 2021/10/21
 * Time: 12:03
 */
namespace app\admin\model;

use think\Model;

class Category extends Model
{
    public static function getCategory($parentid)
    {
        $cate = Category::order('sort')->where('parentid','=',"{$parentid}")->select();

        return $cate;
    }

    public static function getCategoryl($parentid)
    {
        $cateal = Category::distinct(true)->column('parentid');
        return $cateal;
    }

    //新增
    public static function CateAdd($cate)
    {
        try{
            $res = Category::create($cate);
            $msg = '添加成功';
        }catch (\Exception $e){
            $res = false;
            $msg = $e->getMessage();
        }
        return [$res,$msg];
    }

    public static function Catego()
    {
        $cate = Category::where('parentid','=',0)->select();
        return $cate;
    }

    public static function editCate($id)
    {
        $cate = Category::where('id','=',$id)->find()->toArray();
        return $cate;
    }

    public static function CateEdit($data,$id)
    {
        try{
            $res = Category::where('id','=',$id)->update($data);
            $msg = '修改成功';
        }catch (\Exception $e){
            $res = false;
            $msg = $e->getMessage();
        }
        return [$res,$msg];
    }


}





















